<?php
session_start();
class Request{
	var $unit;
	var $message;

	function connect(){
		$user="root";
		$password="";
		$database="whitehouse";
		mysql_connect(localhost,$user,$password);
		@mysql_select_db($database) or die("Unable to select database");
	}

	function addRequest($request){
		$message = $request['message'];
		$unit = $request['unit'];
		$query = "INSERT into request(message,date_sent,unit) values ('$message',curdate(),'$unit')";
		mysql_query($query);
	}
	
	function getRequest($id){
		$query = "SELECT * from request where id = $id";
		$result = mysql_query($query);
		$row = mysql_fetch_array( $result );
		$request['id'] = $row['id'];
		$request['message'] = $row['message'];
		$request['date_sent'] = $row['date_sent'];
		$request['unit'] = $row['unit'];
		return $request;
	}
	
	function getList(){
		if($_SESSION['username']=="admin"){
			$query = "SELECT * from request";
		}
		else {
			$unit = $_SESSION['username'];
			$query = "SELECT * from request where unit='$unit'";
		}
		
		$result = mysql_query($query);
		$i=0;
		while($row = mysql_fetch_array( $result )){
		//	echo $row['unit']."<br />";
			//echo $row['id']."<br />";
			$list[$i]['id']=$row['id'];
			$list[$i]['unit']=$row['unit'];
			$i++;
		}
		return $list;
	}
	
	function deleteManyRequests($ids){
		for($i=0;$i<count($ids);$i++){
			$temp = $ids[$i];
			$query = "DELETE from request where id = $temp";
			mysql_query($query);
		}
	}

}
?>